#include <stdio.h>
#include <fcntl.h>
#include <devctl.h>


typedef struct {
    int value;
} my_devctl_data_t;

#define MY_DEVCTL_CMD_INPUT  	__DIOT(_DCMD_MISC, 0x54 + 1, my_devctl_data_t)
#define MY_DEVCTL_CMD_OUTPUT	__DIOF(_DCMD_MISC,  0x01 + 1, my_devctl_data_t)

int main() {
    int fd = open("/dev/test", O_RDWR);
    if (fd == -1) {
        perror("open");
        return -1;
    }

    // 测试输入命令
    my_devctl_data_t input_data;
    input_data.value = 123;
    if (devctl(fd, MY_DEVCTL_CMD_INPUT, &input_data, sizeof(input_data), NULL) == -1) {
        perror("devctl input");
        close(fd);
        return -1;
    }

    // 测试输出命令
    my_devctl_data_t output_data;
    if (devctl(fd, MY_DEVCTL_CMD_OUTPUT, &output_data, sizeof(output_data), NULL) == -1) {
        perror("devctl output");
        close(fd);
        return -1;
    }
    printf("Received output value: %d\n", output_data.value);

    close(fd);
    return 0;
}
